Repository navigation
fix: keep set operations after subquery operands at the outer query - #914
Merged
Merged
Conversation
The SQL parser attached a UNION, EXCEPT or INTERSECT that followed a parenthesized subquery operand, such as `WHERE x < (SELECT ...)`, to the subquery instead of the outer SELECT. Compile then raised a false B216 column-count error, and the formatter indented the set operation under the predicate. Bump polyglot-sql to the parser fix and cover compile, build, Rules and format through the CLI on DuckDB, plus formatter layout across dialects.
Bump polyglot-sql to linear set-operation scope building. SQL tests whose fixtures are long UNION ALL chains previously grew quadratically in compile analysis; 400-row fixtures now analyze in a fraction of the time. Add a performance guard comparing native analysis time for 50- and 200-row UNION ALL fixtures across several SQL tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A set operation after a parenthesised subquery in an expression (
WHERE a.x < (SELECT …) UNION ALL SELECT …, and the same in HAVING, JOIN ON or BETWEEN) was parsed as part of the subquery. That caused a false B216 column-count error and mis-indentedUNION ALLinsqb format(CHI-473). Separately, SQL tests whose fixtures are longUNION ALLchains were analysed in quadratic time (CHI-475).Changes
polyglot-sqlto fix: keep set operations after subquery operands at the outer query; build set-operation scopes in linear time polyglot#32, which fixes the parse and builds set-operation scopes in linear time.sqb formatand a recompile are clean, and a real column-count mismatch still raises B216.UNION ALLfixtures stays under 6x (new about 3x, old pin 19x).Verification
make test,make check-ci.